{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:4: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead\n",
      "  after removing the cwd from sys.path.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>HrMn</th>\n",
       "      <th>Dir</th>\n",
       "      <th>Spd</th>\n",
       "      <th>Temp</th>\n",
       "      <th>Dewpt</th>\n",
       "      <th>Slp</th>\n",
       "      <th>Dir.1</th>\n",
       "      <th>Spd.1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1973-01-01</td>\n",
       "      <td>0</td>\n",
       "      <td>320</td>\n",
       "      <td>4.0</td>\n",
       "      <td>-11.0</td>\n",
       "      <td>-21.0</td>\n",
       "      <td>1020.2</td>\n",
       "      <td>320.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1973-01-01</td>\n",
       "      <td>300</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-8.0</td>\n",
       "      <td>-25.0</td>\n",
       "      <td>1021.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1973-01-01</td>\n",
       "      <td>600</td>\n",
       "      <td>340</td>\n",
       "      <td>7.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>-25.0</td>\n",
       "      <td>1020.5</td>\n",
       "      <td>340.0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1973-01-01</td>\n",
       "      <td>900</td>\n",
       "      <td>320</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-9.0</td>\n",
       "      <td>-27.0</td>\n",
       "      <td>1021.1</td>\n",
       "      <td>320.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1973-01-01</td>\n",
       "      <td>1500</td>\n",
       "      <td>340</td>\n",
       "      <td>5.0</td>\n",
       "      <td>-15.0</td>\n",
       "      <td>-27.0</td>\n",
       "      <td>1023.7</td>\n",
       "      <td>340.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135921</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>900</td>\n",
       "      <td>80</td>\n",
       "      <td>1.7</td>\n",
       "      <td>-12.7</td>\n",
       "      <td>-20.4</td>\n",
       "      <td>1033.1</td>\n",
       "      <td>80.0</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135922</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1200</td>\n",
       "      <td>219</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-15.9</td>\n",
       "      <td>-20.3</td>\n",
       "      <td>1033.2</td>\n",
       "      <td>219.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135923</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1500</td>\n",
       "      <td>19</td>\n",
       "      <td>1.3</td>\n",
       "      <td>-19.8</td>\n",
       "      <td>-22.7</td>\n",
       "      <td>1033.1</td>\n",
       "      <td>19.0</td>\n",
       "      <td>1.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135924</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1800</td>\n",
       "      <td>351</td>\n",
       "      <td>1.1</td>\n",
       "      <td>-19.2</td>\n",
       "      <td>-22.4</td>\n",
       "      <td>1031.7</td>\n",
       "      <td>351.0</td>\n",
       "      <td>1.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135925</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>2100</td>\n",
       "      <td>306</td>\n",
       "      <td>1.1</td>\n",
       "      <td>-19.4</td>\n",
       "      <td>-22.1</td>\n",
       "      <td>1031.2</td>\n",
       "      <td>306.0</td>\n",
       "      <td>1.1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>135926 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Date  HrMn  Dir  Spd  Temp  Dewpt     Slp  Dir.1  Spd.1\n",
       "0      1973-01-01     0  320  4.0 -11.0  -21.0  1020.2  320.0    4.0\n",
       "1      1973-01-01   300    0  0.0  -8.0  -25.0  1021.6    NaN    NaN\n",
       "2      1973-01-01   600  340  7.0  -7.0  -25.0  1020.5  340.0    7.0\n",
       "3      1973-01-01   900  320  1.0  -9.0  -27.0  1021.1  320.0    1.0\n",
       "4      1973-01-01  1500  340  5.0 -15.0  -27.0  1023.7  340.0    5.0\n",
       "...           ...   ...  ...  ...   ...    ...     ...    ...    ...\n",
       "135921 2020-01-01   900   80  1.7 -12.7  -20.4  1033.1   80.0    1.7\n",
       "135922 2020-01-01  1200  219  1.0 -15.9  -20.3  1033.2  219.0    1.0\n",
       "135923 2020-01-01  1500   19  1.3 -19.8  -22.7  1033.1   19.0    1.3\n",
       "135924 2020-01-01  1800  351  1.1 -19.2  -22.4  1031.7  351.0    1.1\n",
       "135925 2020-01-01  2100  306  1.1 -19.4  -22.1  1031.2  306.0    1.1\n",
       "\n",
       "[135926 rows x 9 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import math\n",
    "import time\n",
    "start = time.clock()\n",
    "\n",
    "df = pd.read_excel('zhangwu.xlsx').drop(columns = ['Unnamed: 0'])\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "process down\n"
     ]
    }
   ],
   "source": [
    "df['Date'] = pd.to_datetime(df['Date'], format = '%Y-%m-%d')\n",
    "df['month'] = df['Date'].apply(lambda x : x.strftime('%m'))\n",
    "df = df.sort_values(by=['month','Date'])\n",
    "\n",
    "df['x'] = df.apply(lambda x: math.sin(x['Dir']) * x['Spd'], axis=1)\n",
    "df['y'] = df.apply(lambda x: math.cos(x['Dir']) * x['Spd'], axis=1)\n",
    "df['wind_energy'] = df.apply(lambda x: 0.5 * 1.225 * math.pow(x['Spd'],2), axis=1)\n",
    "\n",
    "dfs = df.describe(include='all')\n",
    "\n",
    "df['Date'] = df['Date'].apply(lambda x : x.strftime('%Y-%m-%d')).apply(str)\n",
    "\n",
    "df1 = df.loc[df['month'] == '01'].drop(columns = ['month'])\n",
    "df2 = df.loc[df['month'] == '02'].drop(columns = ['month'])\n",
    "df3 = df.loc[df['month'] == '03'].drop(columns = ['month'])\n",
    "df4 = df.loc[df['month'] == '04'].drop(columns = ['month'])\n",
    "df5 = df.loc[df['month'] == '05'].drop(columns = ['month'])\n",
    "df6 = df.loc[df['month'] == '06'].drop(columns = ['month'])\n",
    "df7 = df.loc[df['month'] == '07'].drop(columns = ['month'])\n",
    "df8 = df.loc[df['month'] == '08'].drop(columns = ['month'])\n",
    "df9 = df.loc[df['month'] == '09'].drop(columns = ['month'])\n",
    "df10 = df.loc[df['month'] == '10'].drop(columns = ['month'])\n",
    "df11 = df.loc[df['month'] == '11'].drop(columns = ['month'])\n",
    "df12 = df.loc[df['month'] == '12'].drop(columns = ['month'])\n",
    "dfmerge1 = pd.concat([df3,df4,df5,df6,df7])\n",
    "dfmerge2 = pd.concat([df1,df2,df8,df9,df10,df11,df12])\n",
    "\n",
    "print (\"processing complete\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "write over\n"
     ]
    }
   ],
   "source": [
    "with pd.ExcelWriter('zhangwu_wind_output_1.xlsx') as writer: \n",
    "    dfs.to_excel(writer, sheet_name='summary')\n",
    "    df.drop(columns = ['month']).to_excel(writer, sheet_name='00',index=None)\n",
    "    df1.to_excel(writer, sheet_name='01', index=None)\n",
    "    df2.to_excel(writer, sheet_name='02', index=None)\n",
    "    df3.to_excel(writer, sheet_name='03', index=None)\n",
    "    df4.to_excel(writer, sheet_name='04', index=None)\n",
    "    df5.to_excel(writer, sheet_name='05', index=None)\n",
    "    df6.to_excel(writer, sheet_name='06', index=None)\n",
    "    df7.to_excel(writer, sheet_name='07', index=None)\n",
    "    df8.to_excel(writer, sheet_name='08', index=None)\n",
    "    df9.to_excel(writer, sheet_name='09', index=None)\n",
    "    df10.to_excel(writer, sheet_name='10', index=None)\n",
    "    df11.to_excel(writer, sheet_name='11', index=None)\n",
    "    df12.to_excel(writer, sheet_name='12', index=None)\n",
    "    dfmerge1.to_excel(writer, sheet_name='3-7', index=None)\n",
    "    dfmerge2.to_excel(writer, sheet_name='8-2', index=None)\n",
    "    \n",
    "print (\"write over\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running time: 108.27698020000001 Seconds\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    }
   ],
   "source": [
    "end = time.clock()\n",
    "print('Running time: %s Seconds'%(end-start))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
